package com.xzx.masterslave.masterslave.context;

import com.xzx.masterslave.masterslave.contast.DataSouceType;
import lombok.extern.slf4j.Slf4j;

/**
 * 数据源 上下文 存储
 */
@Slf4j
public class DataSouceContextHolder {
    private static final ThreadLocal<String> STRING_THREAD_LOCAL = new ThreadLocal<>();


    public static ThreadLocal<String> getStringThreadLocal(){
        return STRING_THREAD_LOCAL;
    }

    public static void read() {
        log.info("ThreadLocalType====>"+DataSouceType.read.getType());
        STRING_THREAD_LOCAL.set(DataSouceType.read.getType());
    }

    public static void write() {
        log.info("ThreadLocal====>"+DataSouceType.write.getType());
        STRING_THREAD_LOCAL.set(DataSouceType.write.getType());
    }

    public static String getJdbcType() {
        return STRING_THREAD_LOCAL.get();
    }
}
